import http.client
import urllib
import json
import requests

#url = 'http://tbhmaiza01.wiifnz6.c35.542b.top/btcserver/myserver.php'
url = 'http://www.bgjvip.com/btcserver/myserver.php'
url2 = 'http://127.0.0.1/btcserver/myserver.php'

def httpGet(resource,params=''):
    conn = http.client.HTTPSConnection(url, timeout=10)
    conn.request("GET",resource + '/' + params, verify=False )
    response = conn.getresponse()
    data = response.read().decode('utf-8')
    return json.loads(data)

def GetUserInfo():
    params = {'act': 'getuserinfo'}
    return httpPost(url,params)

def GetMarket():
    params = {'act': 'getmarket'}
    return httpPost(url2,params)

def Initial(user,the_time,total,totalv):
    params = {'act': 'initial',
              'user': user,
              'the_time': the_time,
              'total': str(total),
              'totalv': totalv
              }
    return httpPost(url, params)

def Insert(user,the_time,total,totalv,shouyi,shouyiv,shouyiup):
    params = {'act': 'insert',
              'user': user,
              'the_time': the_time,
              'total': str(total),
              'totalv': totalv,
              'shouyi': str(shouyi),
              'shouyiv': shouyiv,
              'shouyiup': shouyiup
              }
    return httpPost(url, params)

def Update(user,the_time,total,totalv,shouyi,shouyiv):
    params = {'act': 'update',
              'user': user,
              'the_time': the_time,
              'total': str(total),
              'totalv': totalv,
              'shouyi': str(shouyi),
              'shouyiv': shouyiv
              }
    return httpPost(url, params)

def Gettotalcoins(user,the_time):
    params = {'act': 'gettotalcoins',
              'user': user,
              'the_time': the_time
              }
    return httpPost(url, params)

def Fencheng(user,the_time,price):
    params = {'act': 'charge',
              'user': user,
              'the_time': the_time,
              'price': price
              }
    return httpPost(url, params)

def Coinprice(prices):
    params = {'act': 'prices',
              'prices': str(prices)
              }
    return httpPost(url, params)

def GetCoinprice():
    params = {'act': 'getcoinprice'
              }
    return httpPost(url, params)

def httpPost(url,params):
    data = requests.post(url, headers={}, data=params, verify=False)
    #print(data.content)
    return data.json()

if __name__ == '__main__':
    Fencheng('18653607730', 17549, 60)